# Replication of Known Unknowns: Media Bias in the Study of Political Violence
# Nick Dietrich (dietrich.nicholas@gmail.com)
# combining variable importance scores
# this takes the files output by ucdp_cforest.R; must be in the same directory as those files and cforest_combine.pbs
# developed in R version 3.4

#Set the path to the directory where ucdp_cforest.R outputs files
setwd("/storage/home/nmd184/cforest_ucdp")

# variable importance
med <- read.csv("cforest_imp_boot_1.csv")
for(i in 2:10){
  tmp <- read.csv(paste0("cforest_imp_boot_",i,".csv"))
  med <- rbind(med,tmp)
}
write.csv(med,file="variable_importance.csv")
rm(med)

# partial dependence
for(ll in 1:10){
  for(i in 1:20){
    this_med <- read.csv(paste0("cforest_pd_boot_",ll,"_",i,".csv"))
    if(exists("pd_med")==F){
      pd_med <- this_med
    } else pd_med <- rbind(pd_med,this_med)
  }
}

write.csv(pd_med,file="partial_dependence.csv")